package com.ling.pl.core.crypto;

import javax.crypto.BadPaddingException;
import javax.crypto.IllegalBlockSizeException;
import javax.crypto.NoSuchPaddingException;
import java.security.InvalidKeyException;
import java.security.NoSuchAlgorithmException;
import java.security.interfaces.RSAPrivateKey;
import java.security.interfaces.RSAPublicKey;

public class BidirectionalEncryptionUtils {
    public static String DESEncrytor(String str) throws InvalidKeyException,
            IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
        return new String(new DESEncryption().encrypt(str));
    }

    public static String DESDecryptor(String str) throws InvalidKeyException,
            IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
        return new String(new DESEncryption().decrypt(str.getBytes()));
    }

    public static String DES3Encrytor(String str) throws InvalidKeyException,
            IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
        return new String(new DES3Encryption().encrypt(str));
    }

    public static String DES3Decryptor(String buff) throws InvalidKeyException,
            IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
        return new String(new DES3Encryption().decrypt(buff.getBytes()));
    }

    public static String AESEncrytor(String str) throws InvalidKeyException,
            IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
        return new String(new AESEncryption().encrypt(str));
    }

    public static String AESDecryptor(String buff) throws InvalidKeyException,
            IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
        return new String(new AESEncryption().decrypt(buff.getBytes()));
    }

    public static String RSAEncrytor(RSAPublicKey publicKey, String srcBytes) throws InvalidKeyException,
            IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
        return new String(new RSAEncryption().encrypt(publicKey, srcBytes.getBytes()));
    }

    public static String RSADecryptor(RSAPrivateKey privateKey, String srcBytes) throws InvalidKeyException,
            IllegalBlockSizeException, BadPaddingException, NoSuchAlgorithmException, NoSuchPaddingException {
        return new String(new RSAEncryption().decrypt(privateKey, srcBytes.getBytes()));
    }
}
